package org.dromara.system.controller.device;

import cn.dev33.satoken.annotation.SaCheckPermission;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.dromara.system.domain.bo.DeviceAlarmBo;
import org.dromara.system.domain.bo.ProcessDeviceAlarmBo;
import org.dromara.system.domain.vo.DeviceAlarmVo;
import org.dromara.system.service.IDeviceAlarmService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 设备报警
 *
 * @author Lion Li
 * @date 2024-10-21
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/alarm")
public class DeviceAlarmController extends BaseController {

    private final IDeviceAlarmService deviceAlarmService;

    /**
     * 查询设备报警列表
     */
    @SaCheckPermission("system:alarm:list")
    @GetMapping("/list")
    public TableDataInfo<DeviceAlarmVo> list(DeviceAlarmBo bo, PageQuery pageQuery) {
        return deviceAlarmService.queryPageList(bo, pageQuery);
    }

    /**
     * 获取设备报警详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("system:alarm:list")
    @GetMapping("/{id}")
    public R<DeviceAlarmVo> getInfo(@NotNull(message = "主键不能为空")
                                    @PathVariable Long id) {
        return R.ok(deviceAlarmService.queryById(id));
    }

    @SaCheckPermission("system:alarm:list")
    @PutMapping("/{id}")
    public R<Boolean> save(@NotNull(message = "主键不能为空")
                           @PathVariable Long id, @RequestBody ProcessDeviceAlarmBo bo) {
        return R.ok(deviceAlarmService.processAlarm(id, bo));
    }



}
